//===========================================================================================
#include <dylab/utils/geometry/EdgeGeometry3.h>
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void runPointInTriangleTest(const EdgeGeometry3 & _edgeGeom, const Vector3 & _p, const EdgeGeometry3::pointcls_t & _correctCls)
{
    EdgeGeometry3::pointcls_t pointCls = _edgeGeom.classifyPoint(_p);

    // test, if cetner is inside based on barycentric coords    
    DYLAB_LOGF3("\t\t classifyPoint(%1%) = %2% (correctCls = %3%)", _p, pointCls, _correctCls);

    // verify point classification
    DYLAB_VERIFY(pointCls.first == _correctCls.first);
    switch (pointCls.first)
    {
    case Math::POINTCLS_VERTEX:
        DYLAB_VERIFY(pointCls.second == _correctCls.second);
        break;
    }    
}
//-----------------------------------------------------------------------------
void runEdgeTests(const EdgeGeometry3 & _edgeGeom)
{ DYLAB_TRACE_CALLS

    // log tested triangle info
    DYLAB_LOGF("Testing _edgeGeom: %1% ... ", _edgeGeom);

    // print its vertices
    for (EdgeGeometry3::VertexIdxIterator vertexIdx; vertexIdx.isValid(); vertexIdx++)
    {
        DYLAB_LOGF("\tcontains vertex: %1%", _edgeGeom[vertexIdx]);

        // and check, if they are inside
        runPointInTriangleTest(_edgeGeom, _edgeGeom[vertexIdx], EdgeGeometry3::pointcls_t(Math::POINTCLS_VERTEX, *vertexIdx));
    }

    DYLAB_LOG("\n");

    // compute value & volume of the triangle
    DYLAB_LOGF("\tcomputeLength() = %1%", _edgeGeom.computeLength());

    // degeneration test
    DYLAB_LOGF("\tisDegenerated() = %1%", _edgeGeom.isDegenerated());
    DYLAB_VERIFY(!_edgeGeom.isDegenerated());

    // compute triangle center
    DYLAB_LOGF("\tcomputeCenter() = %1%", _edgeGeom.computeCenter());

    // compute barycetric coords of the its cetner
    real_t t;
    bool valid = _edgeGeom.computeParameter(_edgeGeom.computeCenter(), t);
    DYLAB_LOGF2("\tcomputeParameter(computeCenter()) = %1% (valid=%2%)", t, valid);
    DYLAB_VERIFY(Math::almostEqual(t, Math::ONE / DYLAB_R(2)));
    DYLAB_VERIFY(valid);

    // check, if the center is inside its triangle
    runPointInTriangleTest(_edgeGeom, _edgeGeom.computeCenter(), EdgeGeometry3::pointcls_t(Math::POINTCLS_INNER, (EdgeGeometry3::vertexidx_t)-1));
}
//===========================================================================================